package com.yanqu.road.dao.impl.activity.celebration;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.celebration.CelebrationScoreConfig;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Author cwq
 * @Data 2021/7/12 17:40
 */
public class CelebrationConfigDaoImpl extends TempDao {

    private static String getCelebrationScoreConfigSql = "select * from `t_s_activity_celebration_score` where `activityId`=? ORDER BY `id` DESC";
    public List<CelebrationScoreConfig> getCelebrationScoreConfigList(int activityId) {
        List<CelebrationScoreConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getCelebrationScoreConfigSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                CelebrationScoreConfig celebrationScoreConfig = new CelebrationScoreConfig();
                celebrationScoreConfig.setActivityId(rs.getInt("activityId"));
                celebrationScoreConfig.setId(rs.getInt("id"));
                celebrationScoreConfig.setScore(rs.getString("score"));
                celebrationScoreConfig.setAppearanceId(rs.getString("appearanceId"));
                list.add(celebrationScoreConfig);

                // 解析配置
                celebrationScoreConfig.timesList = StringUtils.stringToLongList(celebrationScoreConfig.getScore(),"\\|");
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }




}
